package managers.dateManager.endFrozen.durationChange;

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.log4j.Logger;
import org.tbjd.client.beans.Task;
import org.tbjd.client.constants.NotificationsConstants;
import org.tbjd.client.exceptions.TaskManagerException;
import org.tbjd.client.managers.TaskManager;
import org.tbjd.client.states.StateBeginFrozenSPEC;

import factories.TaskFactory;

/**
 * <p>
 * Test TaskManager's methods
 * </p>
 * <p>
 * <b>Case</b>
 * </p>
 * <p>
 * Task with EndDate frozen and no relationships (predecessors/successors)
 * </p>
 * <p>
 * <b>Action</b>
 * </p>
 * <p>
 * Change duration of the task "task" with a negative value
 * </p>
 * <p>
 * <b> Expected</b>
 * <ul>
 * <li>throw an exception</li>
 * </ul>
 * </p>
 * 
 * @author Michael Martin
 * @author Antonio Carrozzini
 * @version 1.0
 */
public class EndFrozen_DurationChange_Exceptions extends TestCase {

	private Task task = null;
	private Map<Integer, Object> map = null;
	private Logger log = Logger.getLogger("console");
	private TaskManager dateManager = new TaskManager();

	protected void setUp() throws Exception {
		this.task = (Task) TaskFactory.getInstance();
		this.task.setState(new StateBeginFrozenSPEC(task.getState().getDurationModeState()));

		super.setUp();
	}

	public void testExceptions() {
		System.out.println("");
		log.debug(" === testExceptions");

		float newDuration = -48f;
		log.debug("new duration = " + newDuration);

		this.map = new HashMap<Integer, Object>();
		this.map.put(NotificationsConstants.DATEMANAGER_ACTION_duration, newDuration);
		this.map.put(NotificationsConstants.DATEMANAGER_BEAN, this.task);
		this.map.put(NotificationsConstants.DATEMANAGER_SENDER, null);

		log.debug("call TaskManager...");
		try {
			dateManager.manageDates(map);
			fail();

		} catch (TaskManagerException e) {
			System.out.println(e.getMessage());
			assertNotNull(e.getMessage());

		}

	}

}